from time import sleep
from threading import Thread
from datasave import *
from __init__ import *


# 状态机类


class FiniteStateMachine(Thread):
    # 注册状态
    def __init__(self):
        Thread.__init__(self)
        self.stop_thread = False
        self.mode_init = Mode_Init()
        self.mode_openloop = Mode_OpenLoop()
        self.mode_closeloop = Mode_CloseLoop()
        # self.mode_increasepower = Mode_IncreasePower()
        # self.mode_decreasepower = Mode_DecreasePower()
        # self.mode_clean = Mode_Clean()

        self.current_state = self.mode_init

        self.start()

    # 事件触发
    def process_event(self):
        self.current_state = self.current_state.handle(self)

    def run(self):
        while not self.stop_thread:
            sleep(0.1)
            self.process_event()
            # data_save()
